<template>
  <div class="container">
    <div class="time-box">
      <TimerCount :count="h" />
      <span class="sep">:</span>
      <TimerCount :count="m" />
      <span class="sep">:</span>
      <TimerCount :count="s" />
    </div>
  </div>
</template>

<script setup>
import TimerCount from './TimerCount.vue'
import { ref, onMounted, onBeforeUnmount } from 'vue'

const dt = new Date()
const h = ref(dt.getHours())
const m = ref(dt.getMinutes())
const s = ref(dt.getSeconds())
let timerId = null

onMounted(() => {
  timerId = setInterval(() => {
    const dt = new Date()
    h.value = dt.getHours()
    m.value = dt.getMinutes()
    s.value = dt.getSeconds()
  }, 1000)
})

onBeforeUnmount(() => clearInterval(timerId))
</script>

<style scoped>
.container {
  display: flex;
  height: 100%;
  justify-content: center;
  align-items: center;
}

.time-box {
  display: flex;
  height: 100px;
}

.sep {
  font-size: 50px;
  line-height: 80px;
  margin: 0 15px;
}
</style>
